/**
 * This file is released under the GNU General Public License.
 * Refer to the COPYING file distributed with this package.
 *
 * Copyright (c) 2008-2009 WURFL-Pro srl
 */
package net.sourceforge.wurfl.core.request.normalizer.generic;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sourceforge.wurfl.core.request.normalizer.UserAgentNormalizer;

/**
 * Yahoo Babelfish normalizer.
 * 
 * <p>
 * Strips out the "via babelfish.yahoo.com" from the user-agent.
 * </p>
 * 
 * @author WURFL-PRO SRL, Rome, Italy
 * @version $Id: BabelFishNormalizer.java 1045 2009-03-09 15:52:53Z filippo.deluca $
 */
public class BabelFishNormalizer implements UserAgentNormalizer {

	private static final Pattern babelFishPattern = Pattern
			.compile("\\s*\\(via babelfish.yahoo.com\\)\\s*");

	/**
	 * Replace the "via babelfish.yahoo.com" with "".
	 */
	public String normalize(String userAgent) {

		String normalizedUserAgent = userAgent;

		Matcher matcher = babelFishPattern.matcher(userAgent);
		if (matcher.find()) {
			normalizedUserAgent = matcher.replaceAll("");
		}

		return normalizedUserAgent;

	}

}
